<template>
  <div>
      <div class="layui-tab layui-tab-brief">
<!--        <ul class="layui-tab-title" id="LAY_mine">
          <li lay-id="info" class="layui-this">我的资料</li>
          <li lay-id="avatar">头像</li>
          <li lay-id="pass">密码</li>
          <li lay-id="bind">帐号绑定</li>
        </ul>-->
        <div class="layui-tab-content" style="padding: 20px 0;">
          <div class="layui-form layui-form-pane layui-tab-item layui-show">

<!--            <div class="layui-form layui-form-pane layui-tab-item">-->
            <div class="layui-form-item">
              <div class="layui-form-item">
                <label for="L_nowpass" class="layui-form-label">当前密码</label>
                <div class="layui-input-inline">
                  <input v-model="old_password" type="password" id="L_nowpass" name="nowpass" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                  <input v-model="password" type="password" id="L_pass" name="pass" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
              <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                  <input v-model="confirm_password" type="password" id="L_repass" name="repass" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn" key="set-mine" lay-filter="*" lay-submit @click="submitForm">确认修改</button>
              </div>
            </div>

          </div>
        </div>
      </div>
  </div>

</template>

<script>
import {message} from "@/element/message";
import {password} from "@/api/user";

export default {
  name: 'Password',
  props: {
    user: {}
  },
  data () {
    return {
      old_password: '',
      password: '',
      confirm_password: ''
    }
  },
  methods: {
    submitForm: function () {
      if (this.password !== this.confirm_password) {
        message('新密码和确认密码不一致', 'warning')
        return
      }
      // console.log(this.user.id, this.old_password, this.password, this.confirm_password)
      password(this.user.id, this.old_password, this.password, this.confirm_password).then(this.passwordSuc)
    },
    passwordSuc: function (res) {
      // console.log(res)
      message(res.data.msg)
    }
  }
}
</script>